package cn.fl.audit.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.condition.AudGuarPassOpQueryCondition;
import cn.fl.audit.condition.AudPrjPassOpQueryCondition;
import cn.fl.audit.service.IAudGuarPassOpService;
import cn.fl.audit.service.IAudPrjPassOpService;
import cn.fl.audit.service.IAudReturnVisitService;
import cn.fl.audit.vo.AudGuarPassOpVO;
import cn.fl.audit.vo.AudPrjPassOpVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.condition.PrjCstBscInfoQueryCondition;
import cn.fl.project.constant.PrjCstBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstBscInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstBscInfoVO;
import cn.fl.system.constant.SysLogConstant;

/**
 * @Description: 信审通过意见 控制层
 */
@Controller
@RequestMapping("/audit/audPrjPassOp")
public class AudPrjPassOpController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AudPrjPassOpController.class);

	/**
	 * AudPrjPassOp 服务层BEAN
	 */
	@Autowired
	private IAudPrjPassOpService audPrjPassOpService;
	
	/**
	 * 项目客户服务
	 */
	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;
	
	/**
	 * 担保人通过意见服务
	 */
	@Autowired
	private IAudGuarPassOpService audGuarPassOpService;
	
	/**
	 * 信审回访服务
	 */
	@Autowired
	private IAudReturnVisitService audReturnVisitService;
	
	/**
	 * 数据字典API
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	/**
	 * 项目基础信息服务
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	/**
	 * 客户信息服务
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;

	/**
	 * 到信审通过意见预览页面
	 */
	@RequestMapping(value = "/toPreviewPage.do", method = { RequestMethod.GET})
	public ModelAndView toPreviewPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toPreviewPage", "到信审通过意见预览页面.", CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("audit/audPrjPassOp/audCreditPassOpinionPreviewPage");
		String id = request.getParameter("id");
		String projectId = request.getParameter("projectId");
		String proIntId = request.getParameter("proIntId");
		String previewString = "";
		if(StringUtils.isNotEmpty(id)){
			previewString = this.audPrjPassOpService.getPreviewString(Long.valueOf(id));
		}
		view.addObject("previewString", previewString);
		view.addObject("projectId", projectId);
		view.addObject("proIntId", proIntId);
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		String prdTypCd = request.getParameter("prdTypCd");//产品类型
		ModelAndView view = new ModelAndView("/audit/audPrjPassOp/audPrjPassOpAdd");
		view.addObject("id", id);
		view.addObject("projectId", projectId);
		view.addObject("proIntId", proIntId);
		view.addObject("prdTypCd", prdTypCd);
		
		/**预览运营分析*/
		String previewoperationAnalysis  = "";
		if(StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(proIntId)){
			previewoperationAnalysis = this.audPrjPassOpService.getPreviewoperationAnalysis(Long.valueOf(projectId), proIntId);
		}
		view.addObject("previewoperationAnalysis", previewoperationAnalysis);
		
		/**取值信审基础台账:可操作性评价*/
		
		
		
		/**查询刷新页面字段依据*/ 
		if(StringUtils.isNotEmpty(projectId)){
			/**1.项目ID-->客户ID-->客户表信息-->客户类型*/
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(projectId));
			if(null!=prjBscInfoVO){
				Long cstId = prjBscInfoVO.getCstId();
				CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectDetailById(cstId);
				if(null!=cstBscInfoVO){
					//承租人类型
					view.addObject("tenantTypCd", cstBscInfoVO.getCstTypCd());
				}
			}
		}
		
		
		/**下拉数据*/
		//执行政策标准
		List<KeyValueVO> policyStandatrdsCdList = this.audPrjPassOpService.searchPolicyStandatrdsCdList();
		view.addObject("policyStandatrdsCdList", policyStandatrdsCdList);
		//是否符合标准
		List<KeyValueVO> standardCdList = this.audPrjPassOpService.searchStandardCdList();
		view.addObject("standardCdList", standardCdList);
		//执行模板
		List<KeyValueVO> executeTemplateCdList = this.audPrjPassOpService.searchExecuteTemplateCdList();
		view.addObject("executeTemplateCdList", executeTemplateCdList);
		//购车行为
		List<KeyValueVO> buyCdList = this.audPrjPassOpService.searchBuyCdList();
		view.addObject("buyCdList", buyCdList);
		//资产实力
		List<KeyValueVO> lesseeAssetsCdList = this.audPrjPassOpService.searchLesseeAssetsCdList();
		view.addObject("lesseeAssetsCdList", lesseeAssetsCdList);
		view.addObject("lesseeAssetsCdListJSON", JSON.toJSON(lesseeAssetsCdList));
		//车辆配置
		List<KeyValueVO> carConfigCdList = this.audPrjPassOpService.searchCarConfigCdList();
		view.addObject("carConfigCdList", carConfigCdList);
		//融资方案
		List<KeyValueVO> financePlanCdList = this.audPrjPassOpService.searchFinancePlanCdList();
		view.addObject("financePlanCdList", financePlanCdList);
		//运营情况
		List<KeyValueVO> operationSituationCdList = this.audPrjPassOpService.searchOperationSituationCdList();
		view.addObject("operationSituationCdList", operationSituationCdList);
		//运营经验
		List<KeyValueVO> operationExperienceCdList = this.audPrjPassOpService.searchOperationExperienceCdList();
		view.addObject("operationExperienceCdList", operationExperienceCdList);
		//第二还款来源
		List<KeyValueVO> paymentSourceCdList = this.audPrjPassOpService.searchPaymentSourceCdList();
		view.addObject("paymentSourceCdList", paymentSourceCdList);
		//履行职责
		List<KeyValueVO> fulfilCdList = this.audPrjPassOpService.searchFulfilCdList();
		view.addObject("fulfilCdList", fulfilCdList);
		view.addObject("fulfilCdListJSON", JSON.toJSON(fulfilCdList));
		//电话态度
		List<KeyValueVO> attitudeCdList = this.audPrjPassOpService.searchAttitudeCdList();
		view.addObject("attitudeCdList", attitudeCdList);
		//可操作性评价
		List<KeyValueVO> maneuverabilityCdList = this.audPrjPassOpService.searchManeuverabilityCdList();
		view.addObject("maneuverabilityCdList", maneuverabilityCdList);
		//资产证明
		List<KeyValueVO> assetsProveCdList = this.audPrjPassOpService.searchAssetsProveCdList();
		view.addObject("assetsProveCdList", assetsProveCdList);
		view.addObject("assetsProveCdListJSON", JSON.toJSON(assetsProveCdList));
		//与承租人关系
		List<KeyValueVO> relationshipCdList = this.audReturnVisitService.searchRelationshipCdList();
		view.addObject("relationshipCdList", relationshipCdList);
		view.addObject("relationshipCdListJSON", JSON.toJSON(relationshipCdList));
		
		BaseLogUtils.info(logger, "toAddPage", "跳转到新增/修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到动态字段组件页面-信审通过意见-承租人信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toTenantDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toTenantDynamicFldPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audPrjPassOp/audPassOpinionTenantDycPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 到动态字段组件页面-信审通过意见-乘用车增加
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toCarDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toCarDynamicFldPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audPrjPassOp/audPassOpinionCarDycPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 初始化担保人列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/initGuarantorList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initGuarantorList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		//String guarTypCd = request.getParameter("guarTypCd");//担保人类型
		String prjId = request.getParameter("prjId");//项目Id
		String opId = request.getParameter("opId");//通过意见Id
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		/**
		 * 1.根据项目ID查询项目担保人
		 */
		List<PrjCstBscInfoVO> prjCstList = new ArrayList<PrjCstBscInfoVO>();
		if(StringUtils.isNotEmpty(prjId)){
			PrjCstBscInfoQueryCondition prjCstQC = new PrjCstBscInfoQueryCondition();
			prjCstQC.setCstRlTyp(PrjCstBscInfoConstant.CST_Rl_ATTR_GUARANTOR);//客户属性-担保人
			prjCstQC.setPrjId(Long.valueOf(prjId));//项目ID
			//prjCstQC.setCstTypCd(guarTypCd);//客户类型|担保人类型
			prjCstList = this.prjCstBscInfoService.searchList(prjCstQC);
		}
		
		/**
		 * 2.根据通过意见ID查询担保人通过意见
		 */
		List<AudGuarPassOpVO> audGuarList = new ArrayList<AudGuarPassOpVO>();
		if(StringUtils.isNotEmpty(opId)){
			AudGuarPassOpQueryCondition guarPassQC = new AudGuarPassOpQueryCondition();
			guarPassQC.setOpId(Long.valueOf(opId));//通过意见ID
			//guarPassQC.setGuarTypCd(guarTypCd);//担保人类型
			audGuarList = this.audGuarPassOpService.searchList(guarPassQC);
		}
		
		/**
		 * 3.对比两个集合
		 */
		List<AudGuarPassOpVO> audGuarPassOpVOList = new ArrayList<AudGuarPassOpVO>();//最终结果
		if(CollectionUtils.isNotEmpty(audGuarList)){
			audGuarPassOpVOList.addAll(audGuarList);
		}
		for (PrjCstBscInfoVO prjCstBscInfoVO : prjCstList) {
			boolean isExsit = false;//项目担保人是否存在担保人通过意见中
			for (AudGuarPassOpVO audGuarPassOpVO : audGuarList) {
				if(null!=prjCstBscInfoVO && null!=audGuarPassOpVO && prjCstBscInfoVO.getCstId().equals(audGuarPassOpVO.getGuarId())){
					isExsit = true;
					break;
				}
			}
			if(!isExsit){
				AudGuarPassOpVO audGuarPassOpVO = new AudGuarPassOpVO();
				audGuarPassOpVO.setGuarId(prjCstBscInfoVO.getCstId());//担保人ID
				audGuarPassOpVO.setGuarNm(prjCstBscInfoVO.getCstNm());//担保人名称
				audGuarPassOpVO.setGuarTypCd(prjCstBscInfoVO.getCstTypCd());//担保人类型
				audGuarPassOpVOList.add(audGuarPassOpVO);
			}
		}
		/**==========================*/
		List<AudGuarPassOpVO> removeList = new ArrayList<AudGuarPassOpVO>();
		for (AudGuarPassOpVO audGuarPassOpVO : audGuarPassOpVOList) {
			/**
			 * 通过意见担保人 是否有项目担保人里没有的
			 * (如果有是因为信审维护了担保人通过意见之后驳回,呈报人修改了担保人(删除了担保人),在这里页面上去掉,再次点击保存数据库会删掉,不点击数据库不会删掉)
			 */
			boolean isExsit = false;
			for (PrjCstBscInfoVO prjCstBscInfoVO : prjCstList) {
				if(null!=prjCstBscInfoVO && null!=audGuarPassOpVO && prjCstBscInfoVO.getCstId().equals(audGuarPassOpVO.getGuarId())){
					isExsit = true;
					break;
				}
			}
			if(!isExsit){
				removeList.add(audGuarPassOpVO);
			}
		}
		audGuarPassOpVOList.removeAll(removeList);
		//删除数据库多余数据removeList 这里删除失败也没关系  页面保存后自会删除
		if(CollectionUtils.isNotEmpty(removeList)){
			List<Long> removeIds = new ArrayList<Long>();
			for (AudGuarPassOpVO audGuarPassOpVO : removeList) {
				if(StringUtils.isNotEmpty(audGuarPassOpVO.getId())){
					removeIds.add(audGuarPassOpVO.getId());
				}
			}
			if(CollectionUtils.isNotEmpty(removeIds)){
				try {
					this.audGuarPassOpService.removeByIds(removeIds);
				} catch (BaseException e) {
					BaseLogUtils.info(logger, "initGuarantorList", "批量删除担保人通过意见失败.DATA:"+JSON.toJSONString(removeIds)+",ERROR:"+e.getMessage());
				}
			}
		}
		
		/**===========================*/
		
		//设置担保人类型  显示名称
		Map<String, String> cstTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_GRP_CST_TYP_CD);
		if(null!=cstTypCdMap && !cstTypCdMap.isEmpty() && CollectionUtils.isNotEmpty(audGuarPassOpVOList)){
			for (AudGuarPassOpVO audGuarPassOpVO : audGuarPassOpVOList) {
				if(cstTypCdMap.containsKey(audGuarPassOpVO.getGuarTypCd())){
					audGuarPassOpVO.setGuarTypCdNm(cstTypCdMap.get(audGuarPassOpVO.getGuarTypCd()));
				}
			}
		}
		
		
		ListPageVO<AudGuarPassOpVO> listPage = new ListPageVO<AudGuarPassOpVO>(audGuarPassOpVOList, audGuarPassOpVOList.size());
		BaseLogUtils.info(logger, "initGuarantorList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 根据 项目ID|流程实例ID 获取信审通过意见信息
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/getByProjectIdAndProIntId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getByProjectIdAndProIntId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String projectId = request.getParameter("projectId");
		String proIntId = request.getParameter("proIntId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(projectId)||StringUtils.isEmpty(proIntId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_AUD_PROINT_ID_NOT_EMPTY + SysLogConstant.LOG_AUD_PROJECT_ID_NOT_EMPTY);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取数据,缺少必要参数条件.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudPrjPassOpQueryCondition qc = new AudPrjPassOpQueryCondition();
			qc.setProIntId(proIntId);
			qc.setProjectId(Long.valueOf(projectId));
			AudPrjPassOpVO audPrjPassOpVO = this.audPrjPassOpService.selectAudPrjPassOpVOByQc(qc);
			if(null == audPrjPassOpVO){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据,数据不存在.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(audPrjPassOpVO);
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		AudPrjPassOpVO entity = null;
		try {
			entity = this.getRequestParamForAdd(request);
			Long id = this.audPrjPassOpService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		AudPrjPassOpVO entity = null;
		try {
			entity = this.getRequestParamForModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.audPrjPassOpService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	//********************私有方法********************//
	/**
	 * 获取参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private AudPrjPassOpVO getRequestParam(HttpServletRequest request)throws BaseException{
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		if(StringUtils.isEmpty(proIntId)||StringUtils.isEmpty(projectId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID和流程实例ID不能为空.");
		}
		AudPrjPassOpVO audPrjPassOpVO = new AudPrjPassOpVO();
		
		/**信审资料-承租人*/
		String creditInfo = request.getParameter("creditInfo");//信审资料
		String qualificationsInfo = request.getParameter("qualificationsInfo");//资质情况
		String assetsProveCd = request.getParameter("assetsProveCd");//资产证明
		String times = request.getParameter("times");//融资次数
		String badRecordInfo = request.getParameter("badRecordInfo");//不良记录情况
		String courtsEnforceInfo = request.getParameter("courtsEnforceInfo");//法院执行情况
		String researchReport = request.getParameter("researchReport_tenant");//调查报告显示
		String registerTm = request.getParameter("registerTm_tenant");//注册时间
		String business = request.getParameter("business_tenant");//从事业务
		
		/**产品政策*/
		String returnPct = request.getParameter("returnPct");//收益率
		String policyStandatrdsCd = request.getParameter("policyStandatrdsCd");//执行政策标准
		String standardCd = request.getParameter("standardCd");//是否符合标准
		String executeTemplateCd = request.getParameter("executeTemplateCd");//执行模板
		String operationAnalysis = request.getParameter("operationAnalysis");//运营分析
		
		/**信审员评价-承租人*/
		String buyCd = request.getParameter("buyCd");//购车行为
		String lesseeAssetsCd = request.getParameter("lesseeAssetsCd");//承租人资产实力
		String carConfigCd = request.getParameter("carConfigCd");//车辆配置
		String financePlanCd = request.getParameter("financePlanCd");//融资方案
		String operationSituationCd = request.getParameter("operationSituationCd");//运营情况
		String operationExperienceCd = request.getParameter("operationExperienceCd");//运营经验
		String paymentSourceCd = request.getParameter("paymentSourceCd");//第二还款来源
		String managementSituation = request.getParameter("managementSituation");//经营状况
		
		/**风险*/
		String attitudeCd = request.getParameter("attitudeCd");//电话态度
		String riskAnalysis = request.getParameter("riskAnalysis");//风险分析
		String maneuverabilityCd = request.getParameter("maneuverabilityCd");//可操作性评价
		String opinion = request.getParameter("opinion");//审批意见结束语
		
		/**乘用车增加*/
//		String display = request.getParameter("display");//显示
//		String certificates = request.getParameter("certificates");//其他工作证明
//		String incomeExpenditure = request.getParameter("incomeExpenditure");//收入支出情况
//		String isInquiry = request.getParameter("isInquiry");//是否查询征信
//		String overdueInfo = request.getParameter("overdueInfo");//逾期情况
//		String liabilitiesInfo = request.getParameter("liabilitiesInfo");//负债情况
//		String guarantInfo = request.getParameter("guarantInfo");//对外担保情况
//		String isCreditStandard = request.getParameter("isCreditStandard");//征信是否符合我司标准
		
		String otherInfo = request.getParameter("otherInfo");//备注
		
		if(StringUtils.isNotEmpty(projectId)){
			audPrjPassOpVO.setProjectId(Long.valueOf(projectId));
		}
		audPrjPassOpVO.setProIntId(proIntId);
		if(StringUtils.isNotEmpty(returnPct)){
			audPrjPassOpVO.setReturnPct(Double.valueOf(returnPct));
		}
		audPrjPassOpVO.setCreditInfo(creditInfo);
		audPrjPassOpVO.setQualificationsInfo(qualificationsInfo);
		audPrjPassOpVO.setAssetsProveCd(assetsProveCd);
		if(StringUtils.isNotEmpty(times)){
			audPrjPassOpVO.setTimes(Long.valueOf(times));
		}
		audPrjPassOpVO.setBadRecordInfo(badRecordInfo);
		audPrjPassOpVO.setCourtsEnforceInfo(courtsEnforceInfo);
		audPrjPassOpVO.setResearchReport(researchReport);
		if(StringUtils.isNotEmpty(registerTm)){
			audPrjPassOpVO.setRegisterTm(DateUtils.formatStringToDate(registerTm, DateUtils.YYYY_MM_DD));
		}
		audPrjPassOpVO.setBizInfo(business);
		audPrjPassOpVO.setPolicyStandatrdsCd(policyStandatrdsCd);
		audPrjPassOpVO.setStandardCd(standardCd);
		audPrjPassOpVO.setExecuteTemplateCd(executeTemplateCd);
		audPrjPassOpVO.setOperationAnalysis(operationAnalysis);
		audPrjPassOpVO.setBuyCd(buyCd);
		audPrjPassOpVO.setLesseeAssetsCd(lesseeAssetsCd);
		audPrjPassOpVO.setCarConfigCd(carConfigCd);
		audPrjPassOpVO.setFinancePlanCd(financePlanCd);
		audPrjPassOpVO.setOperationSituationCd(operationSituationCd);
		audPrjPassOpVO.setOperationExperienceCd(operationExperienceCd);
		audPrjPassOpVO.setPaymentSourceCd(paymentSourceCd);
		audPrjPassOpVO.setManagementSituation(managementSituation);
		audPrjPassOpVO.setAttitudeCd(attitudeCd);
		audPrjPassOpVO.setRiskAnalysis(riskAnalysis);
		audPrjPassOpVO.setManeuverabilityCd(maneuverabilityCd);
		audPrjPassOpVO.setOpinion(opinion);
		audPrjPassOpVO.setOtherInfo(otherInfo);
		
		/**担保人通过意见*/
		String GuarantorInfoJSON = request.getParameter("GuarantorInfoJSON");//担保人信审资料
		List<AudGuarPassOpVO> GuarantorInfoList = JSON.parseArray(GuarantorInfoJSON, AudGuarPassOpVO.class);//作为最终担保人通过意见集合载体
		
		String GuarantorEvaluateJSON = request.getParameter("GuarantorEvaluateJSON");//担保人信审员评价
		List<AudGuarPassOpVO> GuarantorEvaluateList = JSON.parseArray(GuarantorEvaluateJSON, AudGuarPassOpVO.class);
		
		//遍历把担保人信审员评价相关数值设置到担保人信审资料集合对象里
		if(CollectionUtils.isNotEmpty(GuarantorInfoList) && CollectionUtils.isNotEmpty(GuarantorEvaluateList)){
			for (AudGuarPassOpVO audGuarPassOpVO1 : GuarantorInfoList) {
				for (AudGuarPassOpVO audGuarPassOpVO2 : GuarantorEvaluateList) {
					if(null!=audGuarPassOpVO1 && null!=audGuarPassOpVO2 && audGuarPassOpVO1.getGuarId().equals(audGuarPassOpVO2.getGuarId())){
						audGuarPassOpVO1.setFulfilCd(audGuarPassOpVO2.getFulfilCd());//履行职责
						audGuarPassOpVO1.setBizDesc(audGuarPassOpVO2.getBizDesc());//从事工作/主营业务
						audGuarPassOpVO1.setGuarantorAssetsCd(audGuarPassOpVO2.getGuarantorAssetsCd());//担保人资产实力
					}
				}
			}
		}
		audPrjPassOpVO.setAudGuarPassOpVOList(GuarantorInfoList);
		
		return audPrjPassOpVO;
	}
	
	/**
	 * 获取请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private AudPrjPassOpVO getRequestParamForAdd(HttpServletRequest request)throws BaseException{
		AudPrjPassOpVO audPrjPassOpVO = this.getRequestParam(request);
		audPrjPassOpVO.setCrtTm(new Date());
		audPrjPassOpVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudGuarPassOpVO> audGuarPassOpVOList = audPrjPassOpVO.getAudGuarPassOpVOList();
		if(null!=audGuarPassOpVOList && CollectionUtils.isNotEmpty(audGuarPassOpVOList)){
			for (AudGuarPassOpVO audGuarPassOpVO : audGuarPassOpVOList) {
				audGuarPassOpVO.setCrtTm(new Date());	
				audGuarPassOpVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audPrjPassOpVO;
	}
	
	/**
	 * 获取请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private AudPrjPassOpVO getRequestParamForModify(HttpServletRequest request)throws BaseException{
		AudPrjPassOpVO audPrjPassOpVO = this.getRequestParam(request);
		audPrjPassOpVO.setMdfTm(new Date());
		audPrjPassOpVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudGuarPassOpVO> audGuarPassOpVOList = audPrjPassOpVO.getAudGuarPassOpVOList();
		if(null!=audGuarPassOpVOList && CollectionUtils.isNotEmpty(audGuarPassOpVOList)){
			for (AudGuarPassOpVO audGuarPassOpVO : audGuarPassOpVOList) {
				audGuarPassOpVO.setMdfTm(new Date());	
				audGuarPassOpVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audPrjPassOpVO;
	}
}

